<script type="text/javascript"><!--//--><![CDATA[//><!--
var LOVKomplainMIS = function(ao_option){
	try{
		if(ao_option==undefined){ ao_option={}; }
		var lf_onSelect	= (ao_option.onSelect==undefined || typeof(ao_option.onSelect)!='function') ? function(){} : ao_option.onSelect;
		
		// Create Popup
		var $popup	= openPopup({ title:'Daftar Komplain' , width:700, height:370 });
		var ls_id	= $popup.attr('id');
		
		// Append Datagrid Container
		var ls_gridName	= 'grid_'+ls_id;
		$popup	.html(	$('<div>')	.attr('id', 'tb'+ls_id).attr('style','padding:5px;height:auto;')
									.html(	$('<div>').html($('<form>')	.attr('id','fm_search_'+ls_id).data('rel',ls_id).submit(function(e){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).data('rel')).serializeObject()); e.preventDefault(); })
																		.html('<table class="tb_form" style="margin-bottom:0px"><tr><td width="100">Keyword</td><td><input type="text" name="keyword" class="textfield medium" /><a href="#" class="easyui-linkbutton" iconCls="icon-search" id="btn_search'+ls_id+'" rel="'+ls_id+'">Search</a></td></tr></table>')
															)
											)
						)
				.append($('<div>').attr('id', ls_gridName).attr('toolbar', '#tb'+$popup.attr('id')));
		
		$('#btn_search'+ls_id).click(function(){ $('#'+ls_gridName).datagrid('reload', $('#fm_search_'+$(this).attr('rel')).serializeObject()); return false; });
		$('#btn_search'+ls_id).linkbutton({  
			plain:true  
		}); 
		
		// Build Datagrid
		var ls_param = (ao_option.param==undefined ? '' : ao_option.param);
		$('#'+ls_gridName).datagrid({  
			url:gs_path+'/mis_komplain_penugasan/getdata2/'+ls_param,
			queryParams: $('#fm_search_'+ls_id).serializeObject(),
			height:337,
			pagination:true,
			singleSelect:true,
			columns:[[
				{ field : 'id_komplain', title : 'ID Komplain', width : 100, sortable:true },
				{ field : 'nama_unit', title : 'Nama Unit', width : 100, sortable:true },
				{ field : 'kode_komplain', title : 'Kode Komplain', width : 220, sortable:true },
				{ field : 'komplain', title : 'Komplain', width : 300, sortable:true },
				{ field : 'nama_departemen', title : 'Nama Departemen', width:200, sortable:true },
				{ field : 'tgl_komplain', title : 'Tanggal Komplain', width : 120, sortable:true },
			]],
			onSelect:function(rowIndex, rowData){ lf_onSelect(rowData); closePopup(); }
		});
		
	} catch (err) { alert('Func. LOVSampleReference :\n' + err); }
};

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {

		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center' },
				{ field : 'kode_komplain', title : 'Kode Komplain', width : 220, sortable:true },
				{ field : 'tgl_komplain', title : 'Tanggal Komplain', width : 120, sortable:true },
				{ field : 'nama_unit', title : 'Departemen', width : 200, sortable:true },
				{ field : 'komplain', title : 'Komplain', width : 200, sortable:true },
				{ field : 'nama', title : 'Nama', width : 150, sortable:true },
				{ field : 'status', title : 'Status', width : 150, sortable:true },
				{ field : 'keterangan', title : 'Keterangan', width : 150, sortable:true },
				{ field : 'tgl_selesai', title : 'Tanggal Selesai', width : 120, sortable:true },
			]]
		});		
		
		// Setup Form
		$('#form_master').setupForm([			
			{ name: 'kode_komplain', type: 'lov', size: 'long',  noempty:true,
				onClearButton:function(){
					$(this).setval('');
					$('#id_komplain').setval('');
					$('#nama_unit').setval('');
					$('#komplain').setval('');
					$('#nama_unit').setval('');
					$('#tgl_komplain').setval('');
					$('#id_departemen_pk').setval('');
				},
				onActionButton:function(){ 
					LOVKomplainMIS({ onSelect:function(row){ 
						$('#kode_komplain').setval(row.kode_komplain); 
						$('#id_departemen_pk').setval(row.nama_unit); 
						$('#kode_komplain').setval(row.kode_komplain);
						$('#komplain').setval(row.komplain);
						$('#nama_unit').setval(row.nama_departemen);
						$('#tgl_komplain').setval(row.tgl_komplain);
						$('#id_komplain').setval(row.id_komplain);
					} }); 
				}
			},
			{ name: 'tgl_komplain', type: 'date', noempty:true, noempty:true },
			//{ name: 'kode_customer', data: <?php echo json_encode($arr_customer); ?>, size: 'medium', noempty:true },
			//{ name: 'nik', type: 'text', size:'long', rows:3  },
			{ name: 'nama', type: 'text', size:'long', rows:3, noempty:true  },
			{ name: 'nama_unit', type: 'text', size:'long', noempty:true },
			{ name: 'komplain', type: 'text', size:'long', noempty:true },
			{ name: 'status', type:'combo', size: 'medium', data:<?php echo json_encode($Status); ?> , noempty:true },		
			{ name: 'urutan',value:'', type: 'text', size: 'medium', maxlength: 40, noempty:true },			
			{ name: 'keterangan', type: 'textarea', size:'long', rows:3 },
			{ name: 'tgl_selesai', type: 'date',  },
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:600,
			height:420,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
					//loadPage(gs_path +'/'+controller+'/index/');
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		
		
		// Set Action Button
		var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$.ajax({
								url:gs_path+'/'+controller+'/id_auto',
								type:'POST',
								dataType:'JSON',
								}).done(function(data){
									$('#id_penugasan').setval(data['id_penugasan_auto']);
							});
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Komplain Penugasan');
							$('#kode_komplain, #komplain, #nama_unit, #tgl_komplain, #kode_customer, #komplain, #status, #keterangan, #tgl_selesai').val('');
							$('#kode_komplain').focus();
							$('#komplain, #nama_unit, #tgl_komplain').readonly();
						} },
						{ label: 'Edit', icon: 'edit', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Komplain Penugasan');
								$('#kode_komplain, #komplain, #nama_unit, #tgl_komplain').readonly();
								jsonToForm(oSel); $('#tgl_komplain').focus();
								$('#id_komplain').setval(oSel['id_komplain']);
								$('#id_penugasan').setval(oSel['id_penugasan']);
								//alert(oSel['id_penugasan']);
								$('#id_departemen_pk').setval(oSel['id_departemen_pk']);
							} 
						} },
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['id_penugasan']);
							} 
						}}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:380px;">
	<form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
       	<td><input id="id_komplain" name="id_komplain" type="hidden" />
       		<input id="id_penugasan" name="id_penugasan" type="hidden" />
       		<input id="id_departemen_pk" name="id_departemen_pk" type="hidden" />
       	</td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Kode Komplain</td>
        <td><input id="kode_komplain" /></td>
    </tr>
     <tr>
        <td class="label" style="width:150px">Departement</td>
        <td><input id="nama_unit" /></td>
    </tr>
     <tr>
        <td class="label" style="width:150px">Komplain</td>
        <td><input id="komplain" /></td>
    </tr>
    <tr>
        <td class="label">Tanggal_komplain</td>
        <td><input id="tgl_komplain" /></td>
    </tr>
    <tr>
        <td class="label">Nama Petugas</td>
        <td><input id="nama" /></td>
    </tr> 
    <tr>
        <td class="label">Status</td>
        <td><input id="status" name="status"/></td>
    </tr> 
    <tr>
        <td class="label">Tanggal Selesai</td>
        <td><input id="tgl_selesai" /></td>
    </tr>               
    <tr>
        <td class="label">Keterangan</td>
        <td><input id="keterangan" /></td>
    </tr> 
    </table>
	</form>
</div>